package ability246

import (
    "log"
    "errors"
    "topsdk"
    "topsdk/ability246/request"
    "topsdk/ability246/response"
    "topsdk/util"
)

type Ability246 struct {
    Client *topsdk.TopClient
}

func NewAbility246(client *topsdk.TopClient) *Ability246{
    return &Ability246{client}
}

/*
    抽奖接口
*/
func (ability *Ability246) AlibabaBeneiftDraw(req *request.AlibabaBeneiftDrawRequest,session string) (*response.AlibabaBeneiftDrawResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability246 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("alibaba.beneift.draw",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.AlibabaBeneiftDrawResponse{}
    if(err != nil){
        log.Println("alibabaBeneiftDraw error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    发奖接口
*/
func (ability *Ability246) AlibabaBenefitSend(req *request.AlibabaBenefitSendRequest,session string) (*response.AlibabaBenefitSendResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability246 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("alibaba.benefit.send",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.AlibabaBenefitSendResponse{}
    if(err != nil){
        log.Println("alibabaBenefitSend error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    奖池奖品查询列表
*/
func (ability *Ability246) AlibabaBenefitQuery(req *request.AlibabaBenefitQueryRequest,session string) (*response.AlibabaBenefitQueryResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability246 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("alibaba.benefit.query",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.AlibabaBenefitQueryResponse{}
    if(err != nil){
        log.Println("alibabaBenefitQuery error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
